package com.db.jschool.logging;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

public class FileAppender extends Appender {

	private final BufferedWriter out;
	
	/**
	 * Constructs file appender. Directory for log file must exist
	 * @param name name of appender
	 * @param fileName name of log file
	 * @throws IOException
	 */
	public FileAppender(String name, String fileName) throws IOException {
		super(name);
		out = new BufferedWriter(new FileWriter(fileName));
	}

	@Override
	public void append(String message) throws IOException {
		out.write(message);
		out.flush();
	}
	
	@Override
	public void close() {
		try {
			out.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
	}

}
